<include file="Public/head" />
<style>
    .account_type {
        background: rgba(0, 0, 0, 0) url("{:get_style_cdnurl()}paimai/yunying/images/sanjiao.jpg") no-repeat scroll 100px 5px;
        border: 1px solid #c5c5c5;  display: block;  float: left;  height: 26px;  line-height: 26px;  width: 120px;
    }
    .tanShang .daiJingW{padding: 20px 0 0 10px;}
    .tanShang6{height:220px;}
    .tanShang6 .cardealer-zhanghao{height:30px; line-height:30px;margin:0; text-align:left; overflow:hidden;}
    .tanShang6 .cardealer-zhanghao span{width:90px; text-align:right;float:left; display:block;}
    .tanShang6 .cardealer-zhanghao em{color:#20ab4f;padding:0;font-size:14px;}
    .tanShang6 .cardealer-zhanghao b{display: block;padding-left: 30px;}
    #start_time,#end_time{margin-left: 10px;}
    .account_type {
        background: rgba(0, 0, 0, 0) url("{:get_style_cdnurl()}paimai/yunying/images/sanjiao.jpg") no-repeat scroll 100px 5px;
        border: 1px solid #c5c5c5;  display: block;  float: left;  height: 26px;  line-height: 26px;  width: 120px;
    }
    .tipmsg {font-size:16px;padding-left:5%;}
</style>
<link type="text/css" rel="stylesheet" href="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.css" />
</head>
<include file="Public/common_header" />
<div class="mian">
    <include file="Public/sidebar" menu='zhgl.cszh' />
    <div class="mianR">
        <div class="listBox">
            <form id="fm" action="/CarDealer/user_list" method="GET">
                <div class="yuList">
                    <div class="yuSuo clearfix">
                        <input type="hidden" id="p" name='p' value="" />
                        <input type="text" name='dealer_id' value="{$params.dealer_id}" placeholder="请输入车商ID" class="suoDian" >
                        <input type="text" name='user_name' value="{$params.user_name}" placeholder="请输入车商账号" class="suoDian" >
                        <input type="text" name='contact_person' value="{$params.contact_person}" placeholder="请输入车商联系人" class="suoDian" >
                        <input type="text" name='contact_mobile' value="{$params.contact_mobile}" placeholder="联系人电话"  class="suoDian">
                        <?php if($auth==true):?>
                            <select id="manager_id" name="manager_id" style="float: left;margin-left: 5px;margin-right: 5px;">
                                <option value="0">请选择客户经理</option>
                                <?php foreach($manager_list as $man):?>
                                <option value="{$man.emp_id}">{$man.real_name}</option>
                                <?php endforeach;?>
                            </select>
                            <script>$("#manager_id").val("{$params.manager_id}");</script>
                        <?php endif;?>
                        <select id="business_city" name="business_city" class="account_type" style="margin-left: 5px;">
                            <option value="0">请选择经营城市</option>
                            <volist name="city_list" id="cl">
                                <option value="{$cl.code}" bc-id="{$cl.branch_id}"
                                <?php if ($cl['code'] == $params['business_city']): ?>
                                selected = "selected"
                                <?php endif ?>
                                >{$cl.name}</option>
                            </volist>
                        </select>
                    </div>
                    <div class="yuSuo" style="overflow: hidden;">
                        <select id="bc_id" name="bc_id" class="tracking_list1" style="color:#7f7f7f">
                            <if condition="count($bc_list) gt 1">
                                <option value="-1">请选择分公司</option>
                            </if>
                            <?php if($branch_id==0):?>
                            <option value="0">总部</option>
                            <?php endif;?>
                            <foreach name="bc_list" item="vo" key="k">
                                <option value="{$k}">{$vo}</option>
                            </foreach>
                        </select>
                        <script>$("#bc_id").val("<?php echo $params['bc_id'];?>");</script>
                        <select id="auth_type" name="auth_type" class="account_type" >
                            <option value="-1">请选择车商类型</option>
                            <?php foreach(C('DEALER_CERTIFY_TYPE') as $key=>$val):?>
                            <option value="{$key}" <?php echo $params['auth_type']==$key ? 'selected' :'' ; ?>>{$val}</option>
                            <?php endforeach ?>
                        </select>
                        <script>$("#auth_type").val(<?php echo $params['auth_type'];?>);</script>
                        <select id="dealer_level" name="dealer_level" class="account_type" style="float: left;margin-left: 5px;" >
                            <option value="-1">请选择车商等级</option>
                            <?php foreach(C('DEALER_LEVEL') as $key=>$val):?>
                            <option value="{$key}" <?php echo $params['level']==$key ? 'selected' :'' ; ?>>{$val}</option>
                            <?php endforeach ?>
                        </select>
                        <script>$("#dealer_level").val("{$params.level}");</script>
                        <input type="text" name="start_time" placeholder="开始时间" value="{$params['start_time']}" class="xiaci1 xin-text" id="start_time" readonly>
                        <input type="text" name="end_time"  placeholder="结束时间" value="{$params['end_time']}" class="xiaci1 xin-text" id="end_time" readonly />
                        <select id="jinyong_status" name="jinyong_status" class="account_type" style="float: left;margin-left: 5px;" >
                            <option value="">请选择帐号状态</option>
                            <option value="1" <?php echo $params['status']===1 ? 'selected' :'' ;?> >启用</option>
                            <option value="2" <?php echo $params['status']==2 ? 'selected' :'' ;?> >禁用</option>
                        </select>
                        <input type="button" class="suoSou" onclick="$('#fm #p').val('');$('#fm').submit();" value="搜索"/>
                        <div class="xinzeng clearfix" style="float: left;margin-left: 10px;">
                            <a class="newBtn" href="/CarDealer/add_dealer" style="height: 26px;line-height: 26px;margin-right: 10px;" >新增车商</a>
                        </div>
                        <if condition="$open_auth eq true">
                            <div class="xinzeng clearfix" style="float: left;">
                                <a class="newBtn" href="{:U('CarDealer/open_dealer')}" style="height: 26px;line-height: 26px;margin-right: 10px;">开通车商</a>
                            </div>
                        </if>
                    </div>
                    <div class="yuList">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th width="6%">车商ID</th>
                                    <th width="10%">车商帐号</th>
                                    <th width="8%">联系人</th>
                                    <th width="10%">联系电话</th>
                                    <th width="8%">客户经理</th>
                                    <th width="6%">经营城市</th>
                                    <th width="8%">所属分公司</th>
                                    <th width="6%">车商类型</th>
                                    <th width="6%">车商等级</th>
                                    <!--<th width="6%">所在地</th>-->
                                    <th width="8%">创建时间</th>
                                    <th width="4%">状态</th>
                                    <th width="12%">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                              <?php foreach ($list as $key =>$row): ?>
                                <tr>
                                    <td>{$row.dealer_id}</td>
                                    <td><?php echo $user_list[$row['uid']]['account_name'];?></td>
                                    <td>{$row.contact_person}</td>
                                    <td>{$row.contact_mobile}</td>
                                    <td>{$row.real_name|default='未分配'}</td>
                                    <td>{$row.business_city_name}</td>
                                    <td><?php echo $row['depart_id']>0 ? $row['branch_company'] : '总部' ;?></td>
                                    <td>
                                        <if condition="$row.auth_status eq 2">
                                            <?php echo C("DEALER_CERTIFY_TYPE.".$row['auth_type']);?>
                                            <else />
                                            未认证
                                        </if>
                                    </td>
                                    <td>{$row.level_name}</td>
                                    <td><?php echo $user_list[$row['uid']]['createtime'];?></td>
                                    <td><?php echo $user_list[$row['uid']]['status'] == 1 ? '启用' : '禁用' ;?></td>
                                    <td>
                                      <?php if($edit_auth==true):?>
                                        <a href="/CarDealer/dealer_info/dealer_id/{$row.dealer_id}" target="_blank">查看</a>
                                        <a href="/CarDealer/edit/p/{$p}/dealer_id/{$row.dealer_id}" >编辑</a>
                                        <a href="#" onclick="return reset_pwd('{$row.dealer_id}');">重置</a>
                                        <if condition="($user_list[$row['uid']]['status'] eq 2)">
                                            <a href="#" onclick="return ci_up('{$row.uid}', '{$row.dealer_id}', 1);">启用</a>
                                        <else />
                                            <a href="#" onclick="return ci_up('{$row.uid}', '{$row.dealer_id}', 2);">禁用</a>
                                        </if>
                                        <if condition="($row.dealer_type eq 1)">
                                            <a href="#" onclick="return ci_type('<?php echo $user_list[$row['uid']]['account_name'];?>','{$row.dealer_id}', 0);">内部</a>
                                            <else />
                                            <a href="#" onclick="return ci_type('<?php echo $user_list[$row['uid']]['account_name'];?>','{$row.dealer_id}', 1);">普通</a>
                                        </if>
                                        <if condition="$MoNiDengLu eq 1">
                                            <a  href="/CarDealer/logintolpaiche/dealer_id/{$row.dealer_id}/user_name/<?php echo $user_list[$row['uid']]['account_name'];?>/uid/{$row.uid}" target="_blank" title="模拟登录来拍车">登录</a>
                                        </if>
                                      <?php else:?>
                                        <a href="/CarDealer/dealer_info/dealer_id/{$row.dealer_id}" target="_blank">查看</a>
                                        <?php if($row['emp_id']==$user_info['emp_id']):?>
                                            <a href="/CarDealer/edit/p/{$p}/dealer_id/{$row.dealer_id}" >编辑</a>
                                            <if condition="($user_list[$row['uid']]['status'] eq 2)">
                                                <a href="#" onclick="return ci_up('{$row.uid}', '{$row.dealer_id}', 1);">启用</a>
                                                <else />
                                                <a href="#" onclick="return ci_up('{$row.uid}', '{$row.dealer_id}', 2);">禁用</a>
                                            </if>
                                            <if condition="($row.dealer_type eq 1)">
                                                <a href="#" onclick="return ci_type('{$row.user_name}','{$row.dealer_id}', 0);">内部</a>
                                                <else />
                                                <a href="#" onclick="return ci_type('{$row.user_name}','{$row.dealer_id}', 1);">普通</a>
                                            </if>
                                        <?php endif;?>
                                      <?php endif;?>
                                    </td>
                                </tr>
                              <?php endforeach;?>
                            </tbody>
                        </table>
                    </div>

                    <div class="pageFaye">
                        <div class="pager">
                            {$page_data.totalRows} 条记录 {$page_data.nowPage} /{$page_data.totalPages} 页
                            <span name="first" class="disabled" style="cursor: default;">
                                <a num="{$page_data.first.num}" href="{$page_data.first.url}">首页</a>
                            </span>
                            <span name="prev" class="disabled" style="cursor: default;">
                                <a num="{$page_data.prev.num}" href="{$page_data.prev.url}">上一页</a>
                            </span>
                            <span name="nav_fix" style="cursor: pointer;">
                                <?php foreach ($page_data['link_page'] as $page => $link): ?>
                                <?php if($page == $p){ ?>
                                <a class="navi"  num="<?php echo $page;?>" href="<?php echo $link;?>">
                                    <font style="color:#fff"><?php echo $page;?></font>
                                </a>
                                <?php }else{?>
                                <a class="navi"  num="<?php echo $page;?>" href="<?php echo $link;?>">
                                    <?php echo $page;?>
                                </a>
                                <?php }?>
                                <?php endforeach ?>                                
                            </span>
                            <span name="next" class="pageNext" style="cursor: pointer;"><a num="{$page_data.next.num}"  href="{$page_data.next.url}">下一页</a></span>
                            <span name="last" class="pageLast" style="cursor: pointer;"><a num="{$page_data.end.num}"  href="{$page_data.end.url}">末页</a></span>
                        </div>
                        <div class="clear"></div>
                    </div>
                    <script type="text/javascript">
                        $('#fm .pageFaye a').click(function () {
                            $('#p').val($(this).attr('num'));
                            $('#fm').submit();
                            return false;
                        });
                    </script>
                </div>
            </form>
        </div>
    </div>
    <div class="clear"></div>
    <div class="yunBei" style="display:none"></div>
    <div class="tanShang tanShang6" style="display:none">
        <h3>重置密码</h3>
        <ul class="daiJingW">
            <li class="cardealer-zhanghao">
                <span>
                    联系人：
                </span>
                <em id="dealer_contact_person"></em>
            </li>
            <li class="cardealer-zhanghao">
                <span>
                    手机号：
                </span>
                <em id="dealer_contact_mobile"></em>
            </li>
            <li class="cardealer-zhanghao">
                <b style="color: #FF0000;">确认重置该车商密码？</b>
            </li>
            <li class="clearfix">
                <input type="hidden" name="dealer_id" id="dealer_id">
                <input type="button" value="确定" class="queding" id="qd_reset_pwd"/>
                <input type="button" value="取消" class="quxiao" />
            </li>
        </ul>
    </div>
    <!--设置车商弹出窗口-->
    <div class="tanShang set_dealer_type" style="display:none">
        <h3>车商设置</h3>
        <ul class="daiJingW">
            <li class="clearfix tipmsg"></li>
            <li class="clearfix">
                <input type="hidden" name="dealer_id" id="dealer_id">
                <input type="hidden" name="dealer_type" id="dealer_type">
                <input type="button" value="确定" class="queding" id="qd_ci_op"/>
                <input type="button" value="取消" class="quxiao" />
            </li>
        </ul>
    </div>
</div>
</div>
<div class="tanShang2 popup" style="margin-top: -259.5px;display:none;"></div>
<style>
    .select2-container{width: 128px;}
    .select2-container .select2-choice {
        background: #fff url("{:get_style_cdnurl()}paimai/yunying/images/sanjiao.jpg") no-repeat scroll 100px 5px;
        border: 1px solid #d7d7d7;  color: #444;  display: block;  height: 24px;  line-height: 24px;  overflow: hidden;  padding: 0 0 0 8px;
        position: relative;  text-decoration: none;  white-space: nowrap;  width: 120px;
    }
    .yuSuo .suoDian {  width: 136px;  }
</style>
<script>
    $("#start_time").ymdateplugin({});
    $("#end_time").ymdateplugin({});

    $(function () {
       $("#manager_id").select2();
    });

    function ci_op(username, uid, dealer_id, op_type) {
        var post_data = {username: username, uid:uid, dealer_id:dealer_id, op_type: op_type};
        $.post('/CarDealer/ci_op', post_data, function (res) {
            if (res.code == 200) {
                delay_alert('操作成功!');
                setTimeout(function () {
                    window.location.reload();
                }, 300);
            } else {
                delay_alert(res.msg);
            }
        }, 'json');
        return false;
    };

    function ci_up(uid, dealer_id, up_type) {
        var post_data = {uid: uid, dealer_id: dealer_id, up_type: up_type};
        $.post('/CarDealer/updateUserStatus', post_data, function (res) {
            if (res.code == 200) {
                btn_alert('操作成功!');
                setTimeout(function () {
                    window.location.reload();
                }, 300);
            } else {
                shibai_alert(res.msg);
            }
        }, 'json');
    }

    function reset_pwd(dealer_id){
        $.post('/CarDealer/getDealerUserInfo', {'dealer_id' : dealer_id}, function (res) {
            if (res.code == 200) {
                $("#dealer_contact_person").text(res.data.contact_person);
                $("#dealer_contact_mobile").text(res.data.contact_mobile);
                $("#dealer_id").val(dealer_id);
                $('.tanShang6').show();
            } else {
                shibai_alert(res.msg);
            }
        }, 'json');
    }

    $("#qd_reset_pwd").click(function(){
        $.post('/CarDealer/resetUserPwd', {dealer_id:$('#dealer_id').val()}, function (res) {
            if (res.code == 200) {
                btn_alert('操作成功!');
                setTimeout(function () {
                    window.location.reload();
                }, 300);
            } else {
                shibai_alert(res.msg);
            }
        }, 'json');
    });

    function ci_type(user_name,dealer_id,dealer_type){
        var dealer_type_name = '';
        if(dealer_type == 1){
            dealer_type_name = '内部';
        }else{
            dealer_type_name = '普通';
        }
        var str = '确定将车商<b style="color:red"> ' + user_name + ' </b>设置为' + dealer_type_name + '帐号吗？';
        $('.tipmsg').html(str);
        $('#dealer_id').val(dealer_id);
        $('#dealer_type').val(dealer_type);
        $('.set_dealer_type').show();
//        confirm_alert('<div style="color:red">确定将车商' + user_name + '设置为' + dealer_type_name + '帐号吗？</div>', ci_type_success(dealer_id,dealer_type));
    }


    $('#qd_ci_op').click(function(){
        var dealer_id = $('#dealer_id').val();
        var dealer_type = $('#dealer_type').val();
        var post_data = {
            'dealer_id' : dealer_id,
            'dealer_type' : dealer_type
        }
        $(".yunBei").css("display", "block").unbind('click')
        $(".loading").fadeIn();
        $.post('/CarDealer/changeDealerType',post_data,function(data){
            if(data.code == 200){
                $('.set_dealer_type').hide();
                btn_alert(data.msg);
                setTimeout(function () {
                    window.location.reload();
                }, 300);
            }else{
                $(".loading").fadeOut();
                shibai_alert(data.msg);
            }
        },'JSON');
    });

    function setAccount(did) {
        var bg = $('.yunBei'), ts = $('.tanShang2');
        $.post("/CarDealer/dealer_account", {"did": did}, function (data) {
            if (data == -1) {
                btn_alert("车商信息错误", 1500);
            }
            bg.show();
            ts.html(data).show();
        }, "html");
    }
    $(function () {
        $(".tanShang2").draggable();
    })
</script>
<script src="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.js" type="text/javascript"></script>
<include file="Public/foot" />
